﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Book
{
    public partial class Form1 : Form
    {
        static public string 编号;
        static public string 密码;

        public Form1()
        {
            InitializeComponent();
        }
        private bool pdyj()
        {
            if (textBox1.Text == "")
                return false;
            if (textBox2.Text == "")
                return false;
            return true;
        }
        public void label1_Click(object sender, EventArgs e)
        {

        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {

        }


        private void 登录_Click(object sender, EventArgs e)
        {

            if (radioButton1.Checked)
            {
                if (textBox1.Text.Length == 0)
                {
                    MessageBox.Show("编号不能为空...");
                }
                else if (textBox2.Text.Length == 0)
                {
                    MessageBox.Show("密码不能为空...");
                }
                else
                {
                    string userName = textBox1.Text.Trim();
                    string passWord = textBox2.Text.Trim();
                    OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\zAllstation\access\bookmanage.accdb");
                    con.Open();
                    string cmdStr = "select * from reader where 读者编号='" + this.textBox1.Text + "'and 密码='" + this.textBox2.Text + "'";
                    OleDbCommand cmd = new OleDbCommand(cmdStr, con);
                    OleDbDataReader reader = cmd.ExecuteReader();

                    if (reader.Read()) //如果找到用户信息，说明登录成功
                    {

                        MessageBox.Show("登录成功！");
                        UserHelper.UserName = textBox1.Text;
                        Form3 newForm = new Form3();
                        newForm.Show(); //弹出主窗体                       
                    }
                    else
                    {
                        MessageBox.Show("编号或密码错误!");
                    }
                    reader.Close();
                    con.Close();

                }

            }
            if (radioButton2.Checked)
            {
                if (textBox1.Text.Length == 0)
                {
                    MessageBox.Show("编号不能为空...");
                }
                else if (textBox2.Text.Length == 0)
                {
                    MessageBox.Show("密码不能为空...");
                }
                else
                {
                    string userName = textBox1.Text.Trim();
                    string passWord = textBox2.Text.Trim();
                    OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\zAllstation\access\bookmanage.accdb");
                    con.Open();
                    string cmdStr = "select * from admin where 编号='" + this.textBox1.Text + "'and 密码='" + this.textBox2.Text + "'";
                    OleDbCommand cmd = new OleDbCommand(cmdStr, con);
                    OleDbDataReader reader = cmd.ExecuteReader();

                    if (reader.Read()) //如果找到用户信息，说明登录成功
                    {

                        MessageBox.Show("登录成功！");
                        UserHelper.UserName = textBox1.Text;
                        Form4 newForm = new Form4();
                        newForm.Show(); //弹出主窗体
                    }
                    else
                    {
                        MessageBox.Show("编号或密码错误!");
                    }
                    reader.Close();
                    con.Close();

                }
            }
        }

        private void label5_Click(object sender, EventArgs e)
        {

        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            this.label5.Text = DateTime.Now.ToString();
        }

        private void 注册_Click(object sender, EventArgs e)
        {
            Form2 mainForm2 = new Form2();//实例化第2个界面                         
            mainForm2.Show();//显示第2个界面（用户注册）    
            this.Hide();
        }

        public void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
